/*
* Copyright (C) 2024-2025 Uniontech Technology Co., Ltd.
*
* Author:      zhangbingyi <zhangbingyi@uniontech.com>
*
* Maintainer:  zhangbingyi <zhangbingyi@uniontech.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "schedulescanitem.h"
#include "gsettingkey.h"

#include <QHBoxLayout>
#include <QLabel>
#include <QDebug>

ScheduleScanItem::ScheduleScanItem(QWidget *parent)
    : QWidget(parent)
    , m_lbText(nullptr)
    , m_switchButton(nullptr)

{
    this->setContentsMargins(0, 0, 0, 0);

    initUi();

    initConnection();
}

void ScheduleScanItem::initUi()
{
    // 布局
    QHBoxLayout *layout = new QHBoxLayout;
    layout->setContentsMargins(0, 0, 0, 0);
    setLayout(layout);

    // 设置文本属性
    m_lbText = new QLabel(this);
    m_lbText->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);

    // 设置switch 按钮
    m_switchButton = new HSwitchButton(this);
    m_switchButton->setFixedSize(50, 30);

    // 加入布局
    layout->addWidget(m_lbText);
    layout->addStretch();
    layout->addWidget(m_switchButton);
}

void ScheduleScanItem::initConnection()
{
    // 连接信号槽
    connect(m_switchButton, SIGNAL(statusChanged(bool)), this, SLOT(onStatusChanged(bool)));
}

void ScheduleScanItem::onStatusChanged(bool stage)
{
    Q_EMIT switchTrigger(stage);
}

// 设置文本内容
void ScheduleScanItem::setText(const QString &text)
{
    m_lbText->setText(text);
}

// 设置switch按钮默认状态
void ScheduleScanItem::setSwitchStatus(bool isbStatus)
{
    m_switchButton->setChecked(isbStatus);
}

bool ScheduleScanItem::getSwitchStatus()
{
    return m_switchButton->checked();
}

// 设置switch按钮是否启用
void ScheduleScanItem::enableSwitch(bool enable)
{
    m_switchButton->setEnabled(enable);
}
